package iscript.gameFramework.GameLite.directEvent
{
	import flash.utils.Dictionary;
	
	/**
	 * 监听数据集合
	 */
	internal class DirectEventListenerPool
	{
		
		internal var registerEventName:Vector.<String>;
		internal var registerEventAction:Array;
		
		public function DirectEventListenerPool()
		{
			registerEventName = new Vector.<String>();
			registerEventAction = new Array();
		}
		
		
		public  function get count():int {
			return registerEventName.length;
			}
		
		/**
		 * 添加接受
		 * @param	eventName
		 * @param	action
		 */
		public function add(eventName:String, action:*):void
		{
			if(!hasEvent(eventName,action)){
				registerEventName.push(eventName);
				registerEventAction.push(action);
			}
		}
		
		/**
		 * 存在事件KEY
		 * @param	eventName
		 * @return
		 */
		public function hasEventName(eventName:String):Boolean
		{
			return registerEventName.indexOf(eventName) != -1;
		}
		
		public function hasEvent(eventName:String, action:*):Boolean {
			var index:int = registerEventAction.indexOf(action)    
			if (index == -1) return false
			if (index != -1 && registerEventName[index] != eventName ) return false;
			return true;
			}
		
		
		/**
		 * 移除接收{监听}
		 * @param	eventName
		 * @param	action
		 */
		public function remove(eventName:String, action:*):void
		{
			var index:Vector.<int> = new Vector.<int>();
			for (var i:int = 0; i < registerEventName.length; i++)
			{
				if (registerEventName[i] == eventName && registerEventAction[i] == action)
				{
					index.push(i);
				}
			}
			index.reverse();
			var len:int = index.length - 1;
			var targetIndex:int;
			for (var j:int = len; j >= 0; j--)
			{
				targetIndex = index[j]
				registerEventName.splice(targetIndex, 1);
				registerEventAction.splice(targetIndex, 1);
			}
		}
	
	}

}